package com.jt.controller;

import com.jt.service.ResourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.atomic.AtomicLong;

@RestController
@RequestMapping("/provider")
public class ProviderSentinelController {
    @RequestMapping("/sentinel01")
    public String doSentinel01(){
        return "sentinel 01 test...";
    }
    @RequestMapping("/sentinel02")
    public String doSentinel02(){
        return "sentinel 02 test...";
    }
    @Autowired
    private ResourceService resourceService;
    @RequestMapping("/sentinel03")
    public String doSentinel03(){
        resourceService.doGetResource();
        return "sentinel 03 test...";
    }
    //AtomicLong可以实现自增自减并且线程时安全的
    private AtomicLong atomicLong = new AtomicLong(1);
    @RequestMapping("/sentinel04")
    public String doSentinel04() throws InterruptedException {
        long num = atomicLong.getAndIncrement();
        if(num % 2 ==0){//模拟慢调用
            Thread.sleep(200);
        }
        return "sentinel 04 test...";
    }

}
